<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
<table>
<tr>
    <td><label for="">标题：</label></td>
    <td><input type="text" name="title"></td>

</tr>

<tr>
    <td><label for="">摘要：</label></td>
    <td><input type="text" name="zhaiyao"></td>
    
</tr>
<tr>
    <td><label for="">内容：</label></td>
    <td><input type="text" name="neirong"></td>
    
</tr>
<tr>
    <td><label for="">分类：</label></td>
    <td><input type="text" name="fenlei"></td>
    
</tr>
<tr>
    <td><label for="">作者：</label></td>
    <td><input type="text" name="author"></td>
    
</tr>
<tr>
    <td><input type="button" value="保存" onclick="save()"></td>
    <td><input type="button" value="取消" onclick="cancel()"></td>
    
</tr>
</table>
<script src="./js/jquery-3.6.0.min.js"></script>
<script>
    function save() {
    let obj={
        id:$('[name=id]').val(),
        title:$('[name=title]').val(),
        zhaiyao:$('[name=zhaiyao]').val(),
        neirong:$('[name=neirong]').val(),
        fenlei:$('[name=fenlei]').val(),
        author:$('[name=author]').val(),
        
    }


    if (obj.id) {
        postBlog(obj.id,obj).then(data=>{
        
        console.log(data);
         if (data.code===1000) {
            window.location.href='./index.html';
         }
    })
    }
    
    else{
            postBlog(obj).then(data => {
                    if (data.code === 1000) {
                        window.location.href = './index.html';
                    } else {
                        alert(data.msg)
                    }

                })
        }

}
function cancel() {
    location.href='./index.html'
}
</script>


    </div>
</body>
</html>